import React, { Component } from 'react'
import styles from './index.less'
import { withRouter } from 'dva/router'
import { Layout, Menu } from 'antd'
// import { withRouter } from 'react-router-dom'

const { Sider: MySider } = Layout
const { SubMenu } = Menu;

class Sider extends Component {

    clickMenu = ({ key, keyPath }) => {
        localStorage.removeItem('menuKey')
        if (keyPath) {
            localStorage.menuKey = JSON.stringify(keyPath);
        }
        this.props.history.push(key)
    };

    // renderMenu = menus => {
    // }

    // clickMenu = ({ key, keyPath }) => {
    //     console.log(key);
    //     this.props.history.push(key)
    // }
    render() {
        let menuKey = ['/home/subjectList', 'subject']
        try {
            menuKey = JSON.parse(localStorage.menuKey)
        } catch (error) {
            console.log('menuKey', error);
        }

        return (
            <MySider theme="light" className={styles.sider}>
                <div className={styles.logo}>
                    <span>管理系统</span>
                </div>
                <Menu defaultOpenKeys={[menuKey[1]]} defaultSelectedKeys={[menuKey[0]]} mode="inline" onClick={this.clickMenu}>
                    <SubMenu title="年级管理">
                        <Menu.Item key='/home/gradeList'>年级列表</Menu.Item>
                        <Menu.Item key='/home/gradeAdd'>增加年级</Menu.Item>
                    </SubMenu>
                    <SubMenu key='subject' title="科目管理">
                        <Menu.Item key='/home/addSubject'>新增科目</Menu.Item>
                        <Menu.Item key='/home/subjectList'>科目列表</Menu.Item>
                    </SubMenu>
                    <SubMenu key='manager' title="管理员管理">
                        <Menu.Item key='/home/managerList'>管理员列表</Menu.Item>
                        <Menu.Item key='/home/managerAdd'>增加管理员</Menu.Item>
                    </SubMenu>
                    <SubMenu title="订单管理">
                        <Menu.Item>权限管理</Menu.Item>
                        <Menu.Item >角色管理</Menu.Item>
                    </SubMenu>
                    <SubMenu title="评论管理">
                        <Menu.Item>权限管理</Menu.Item>
                        <Menu.Item >角色管理</Menu.Item>
                    </SubMenu>
                    <SubMenu title="用户管理">
                        <Menu.Item>权限管理</Menu.Item>
                        <Menu.Item >角色管理</Menu.Item>
                    </SubMenu>
                    <SubMenu title="课时管理">
                        <Menu.Item key='/home/addLesson'>新增课时</Menu.Item>
                        <Menu.Item key='/home/lessonList'>课时列表</Menu.Item>
                    </SubMenu>
                    <SubMenu title="课程管理">
                        <Menu.Item key='/home/courseList'>课程列表</Menu.Item>
                        <Menu.Item key='/home/addCourse'>新增课程</Menu.Item>
                    </SubMenu>
                    <SubMenu key='teacher' title="讲师管理">
                        <Menu.Item key='/home/teacherList'>讲师列表</Menu.Item>
                        <Menu.Item key='/home/addTeacher'>新增教师</Menu.Item>
                    </SubMenu>
                    <SubMenu key='role' title="角色管理">
                        <Menu.Item key='/home/addRole'>新增角色</Menu.Item>
                        <Menu.Item key='/home/roleList'>查看角色</Menu.Item>
                    </SubMenu>
                </Menu>
            </MySider>
        )
    }
}

export default withRouter(Sider)
